<?php

declare (strict_types=1);
namespace App\Model;

use App\Constants\Constant;
use Hyperf\DbConnection\Model\Model;
/**
 * @property int $foot_id 
 * @property int $child_id 
 * @property string $child_photo
 * @property string $child_name
 * @property int $is_public
 * @property int $is_excellent 
 * @property int $source 
 * @property int $source_id
 * @property string $source_name
 * @property int $resource_type
 * @property string $content
 * @property string $add_time
 */
class Foot extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'foot';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['child_id','is_public','is_excellent','source','source_id','resource_type','content'];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['foot_id' => 'integer', 'child_id' => 'integer', 'is_public' => 'integer', 'is_excellent' => 'integer', 'source' => 'integer', 'source_id' => 'integer','resource_type'=>'integer'];

    protected $primaryKey = "foot_id";

    public $timestamps = false;

    protected $dates = ['add_time'];

    public function getDateOfAddTimeAttribute(){
        return $this->add_time->toDateString();
    }

    public function getTimeOfAddTimeAttribute(){
        return $this->add_time->toTimeString();
    }

    public function resources(){
        return $this->hasMany(Resource::class,'source_id','foot_id')->where("origin",Constant::ORIGIN_FOOT);
    }

    public function agrees(){
        return $this->hasMany(Agree::class,"source_id","foot_id")->where("origin",Constant::ORIGIN_FOOT);
    }
}